package com.example.factory.core.domain;

import org.apache.commons.collections4.CollectionUtils;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Lei Tao
 */
@Entity
@Table(name = "report_equipment")
public class ReportEquipment extends DomainObject {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "equipment_id")
    private Equipment equipment;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "report_level_1_dimension_id")
    private List<ReportLevel1Dimension> reportLevel1Dimension;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "report_plan_id")
    private ReportPlan reportPlan;

    @Enumerated(value = EnumType.STRING)
    @Column(name = "report_equipment_status")
    private ReportEquipmentStatus reportEquipmentStatus;

    public ReportEquipment() {
    }

    public Equipment getEquipment() {
        return equipment;
    }

    public void setEquipment(Equipment equipment) {
        this.equipment = equipment;
    }

    public ReportPlan getReportPlan() {
        return reportPlan;
    }

    public ReportEquipmentStatus getReportEquipmentStatus() {
        return reportEquipmentStatus;
    }

    public void setReportEquipmentStatus(ReportEquipmentStatus reportEquipmentStatus) {
        this.reportEquipmentStatus = reportEquipmentStatus;
    }

    public void setReportPlan(ReportPlan reportPlan) {
        this.reportPlan = reportPlan;
    }

    public ReportLevel1Dimension getReportLevel1Dimension() {
        if (CollectionUtils.isEmpty(reportLevel1Dimension)) {
            return null;
        }
        return reportLevel1Dimension.get(0);
    }

    public void setReportLevel1Dimension(ReportLevel1Dimension reportLevel1Dimension) {
        if (this.reportLevel1Dimension == null){
            this.reportLevel1Dimension = new ArrayList<>();
        }
        this.reportLevel1Dimension.add(reportLevel1Dimension);
    }

}
